import Vue from 'vue';
import Vuex from 'vuex'
Vue.use(Vuex)
import request from '../common/request';
const store = new Vuex.Store({
	state: {
		user: {}, // 用户信息
		isLogin: false,
		current: 0,
		location: "",
		// district: "",
		list: [
		    {
				iconPath: "coupon",
		        selectedIconPath: "coupon-fill",
		        text: "实体店",
		        customIcon: false,
				path: "/pages/index/index"
		    },
		    {
		        iconPath: "home",
		        selectedIconPath: "home-fill",
		        text: "家事",
		        customIcon: false,
				path: "/pages/work/index"
		    },
		    {
		        iconPath: "account",
		        selectedIconPath: "account-fill",
		        text: "我的",
				customIcon: false,
				path: "/pages/mine/index"
		    },
		]
	},
	// 修改store中的值唯一的方法就是提交mutation来修改
	mutations: {
		/**
		 * 设置状态
		 * @param {Object} state 状态对象
		 * @param {Object} provider 传入值
		 */
		// 用户信息
		userState(state, provider) {
			state.user = provider
		},
		setCurrent(state, current){
			state.current = current
		},
		setLocation(state, provider){
			state.location = provider
		},
		// setDistrict(state, provider){
		// 	state.district = provider
		// }
	},
	actions: {
		// 用户信息
		getUser(context){
			console.log("获取用户信息")
			request("/api/WeChat/getUserByToken", {}, "GET").then(res=>{
				console.log("用户信息", res.data)
				if(res.code===200) context.commit("userState", res.data)
			})
		},
		setUser(context, provider){
			context.commit("userState", provider)
		},
		getCurrent(context, provider){
			context.commit("setCurrent", provider)
		},
		getLocation(context, provider){
			context.commit("setLocation", provider)
		},
		// getDistrict(context, provider){
		// 	context.commit("setDistrict", provider)
		// }
	}
})

export default store